﻿//<TunynetCopyright>
//--------------------------------------------------------------
//<copyright>青岛拓宇网络科技有限公司 2005-2008</copyright>
//<version>V0.5</verion>
//<createdate>2008-3-11</createdate>
//<author>mazq</author>
//<email>mazq@tunynet.com</email>
//<log date="2008-3-11">创建</log>
//--------------------------------------------------------------
//</TunynetCopyright>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChinaCustoms.Qingdao.Workflow.Permissions
{
    public class PermissionUtils
    {
        /// <summary>
        /// 去除集成Windows身份验证的域名信息
        /// </summary>
        public static string StripIrrespectiveCharsForLogOnName(string logOnName)
        {
            if (logOnName.IndexOf("\\") > -1)
                logOnName = logOnName.Substring(logOnName.IndexOf("\\") + 1);

            return logOnName;
        }

        /// <summary>
        /// 去除用户FullPath中无用的部分
        /// </summary>
        /// <example>
        /// "中国海关\青岛海关\技术处\软件开发科\王礼祥" 转换成 "技术处\软件开发科\王礼祥"
        /// </example>        
        public static string FormatUserFullPath(string userFullPath)
        {
            if (string.IsNullOrEmpty(userFullPath))            
                return userFullPath;

            int index = userFullPath.IndexOf(@"中国海关\青岛海关\");
            if (index >= 0)
                userFullPath = userFullPath.Remove(0, 10);

            return userFullPath; 
        }

        /// <summary>
        /// 去除用户FullPath中的用户部分
        /// </summary>
        public static string StripDisplayNameFromUserFullPath(string userFullPath)
        {
            if (string.IsNullOrEmpty(userFullPath))
                return userFullPath;

            int index = userFullPath.LastIndexOf('\\');

            if (index >= 0)
                userFullPath = userFullPath.Remove(index);

            return userFullPath;
        }


    }
}
